<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('日结报表')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .tag {
            display: inline-block;
            padding: 0 5px;
            line-height: 22px;
            color: #FFFFFF;
            border-radius: 3px;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <!--<li>-->
                            <!--物料编码：<input type="text" id="itemCode" name="itemCode"/>-->
                        <!--</li>-->
                        <li>
                            <label>日期：</label>
                            <el-date-picker
                                    name="startTime"
                                    v-model="timeA"
                                    value-format="yyyy-MM-dd"
                                    type="date"
                                    placeholder="选择日期">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="in:boxItem:exportBoxPandect">
                <i class="fa fa-download"></i> 导出全部
            </a>
<!--            <a class="btn btn-info" @click="partExcel()" shiro:hasPermission="in:boxItem:partExcelBoxPandect">-->
<!--                <i class="fa fa-download"></i> 部分导出-->
<!--            </a>-->
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/wms/js/moreSearch.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "in/boxItem";

    const searchOptions = ['物料编码'];

    var app = new Vue({
        el: '.container-div',
        data: {
            timeA: '',
            showMore: false,
            checkAll: false,
            checkedSearch: ['物料编码'],
            searches: searchOptions,
            isIndeterminate: true,
            areas: [],
            checkAreaId: ''
        },
        methods: {
            //获取货区列表
            getAreas: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/areaInfo/list",
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.areas = data.rows;
                        that.checkAreaId = data.rows[0].areaId;
                    }
                });
            },
            today(){
                var date = new Date();
                var Y = date.getFullYear() + '-';
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
                return Y + M + D;
            },
            //部分导出
            partExcel(){
                var that = this;
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectColumns("materialProduct") : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/partExcelBoxPandect";
                        var data = {"ids": rows.join(), "areaId": that.checkAreaId};
                        $.post(url, data, function(result){
                            if(result.code == web_status.SUCCESS){
                                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                            }else if(result.code == web_status.WARNING){
                                $.modal.alertWarning(result.msg);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                            $.modal.closeLoading();
                        });
                    });
                }
            }
        },
        created(){
            this.getAreas();
            this.timeA = this.today();
        }
    })

    $(function () {

        var options = {
            url: prefix + "/boxPandect",
            exportUrl: prefix + "/exportBoxPandect",
            modalName: "日结报表",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    title: '序号',
                    align: 'center',
                    formatter: function(value, row, index){
                        return index + 1;
                    },
                    visible: false
                },
                {
                    field: 'itemCode',
                    title: '物料编码',
                    align: 'center'
                },
                {
                    field: 'itemName',
                    title: '物料描述',
                    align: 'center'
                },
                {
                    field: 'sort',
                    title: '物料类型',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span>钢材</span>");
                        }else if(value == 2){
                            actions.push("<span>铜材</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'inWeight',
                    title: '当日入库重量',
                    align: 'center'
                },
                {
                    field: 'outWeight',
                    title: '当日出库重量',
                    align: 'center'
                },
                {
                    field: 'boxWeight',
                    title: '当日库存重量',
                    align: 'center'
                },
                {
                    field: 'unit',
                    title: '单位',
                    align: 'center'
                },
            ]
        };
        $.table.init(options);
    });

    function queryParams(params){
        let start = new Date();
        start = start.getFullYear() + '-' + (start.getMonth()+1) + '-' + start.getDate();
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            orderByColumn: params.sort,
            isAsc: params.order,
            areaId: app.checkAreaId,
            startTime: start
        };
    }
</script>
</body>
</html>
